//////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // ----------------------------- Ebrahim Foulaadvand, 03 August 2012 ----------------------------------- // // // // The programme "DrivenDampedPedulum" evaluates the temporal evolution of a damped driven pendulum // // by two algorithms Euler-Richardson (ER) and 2nd order Runge-Kutta (RK2). // // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include using namespace std; double a (double &t,double &teta,double &w); // a is the angular accelration function double tau=0.01,T=200,ac,g=9.8,L=g,m=1.,teta0=0.2,w0=0.,gamma=5.,q=gamma/(m*L),omega=0.67,A0=0.9, kteta1,kteta2,lteta1,lteta2,tmid,tetamid,wmid,Anumeric=0.,omegamax=4.,delomega=0.1; // teta0=initial deflection angle, w0=initial angular velocity, tau=timestep; T=simulation time, // E=total energy, L=pendulum length, m=pendulum mass, gamma=damping coefficient, // omega= angular frequency of driving force, A0=sinusoidal driving force amplitude, int N=(T/tau), Nomega=int(omegamax/delomega); // N=number of time step main() { vector w(N+1,0),teta(N+1,0),Acomp(Nomega,0); // Arrays teta and w store the deflection angle and angular velocity at each time step. Array Acomp // stores the pendulum amplitude for a given angular frequency of the sinusoidal driving force. ofstream tetaER("tetaER A0=0.9 free.plt"); // output file of pendulum angle (ER algorithm). ofstream wER("wER.plt"); // output file of pendulum angular velocity (ER algorithm). ofstream tetaRK2("tetaRK2.plt"); // output file of pendulum angle (RK2 algorithm). ofstream wRK2("wRK2.plt"); // output file of pendulum angular velocity (RK2 algorithm). ofstream phaseER("phase-space ER.plt"); // output file for pendulum phase space plot ofstream Ampcomp("Acomp-w gamma=0.5.plt"); // output file for amplitude vs omega //for(int s=0;s(10/q) && t*tau<(10/q) + 2*2*(M_PI/omega) && teta[t]>0 && teta[t+1]>teta[t]) Anumeric=teta[t+1]; }//end t Ampcomp<(10/q) && t*tau<(10/q) + 2*(M_PI/omega) && teta[t]>0 && teta[t+1]>teta[t]) Anumeric=teta[t+1]; }//end t //Ampcomp<